home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HPAVC
/
HPAVC CD-ROM.iso
/
MCASM.RAR
/
MC_ASM.EXE
/
WROX_ASM
/
CH6
/
PROG6_3.ASM
< prev
next >
Wrap
Assembly Source File
|
1994-09-11
|
10KB
|
391 lines
;****************************************
;* *
;* Simple Screen Pencil Program *
;* Author: Yu.I.Petrenko *
;* *
;****************************************
.286
cseg segment BYTE
ORG 100H
assume CS:cseg,DS:cseg,ES:cseg,SS:cseg
START: JMP SET_UP
;=========================================================
;program data
Message1 DB 0Ah,0Dh
DB 'This simple Scren Pencil program is intended',0Ah,0Dh
DB 'for mouse control demonstration.',0Ah,0Dh
DB 'You can use following keys for:',0Ah,0Dh
DB 'SHIFT and mouse left button - to put pencil down,',0Ah,0Dh
DB 'TAB - to switch colors,',0Ah,0Dh
DB 'CapsLock - to trigger wipe UP/DOWN,',0Ah,0Dh
DB 'ESC and right mouse button - exit to DOS',0Ah,0Dh
DB 'Mouse moution and arrow keys cause light dot motion.',0Ah,0Dh
DB 'Best wishes from Author!',0Ah,0Dh
DB 'Please, strike any key ...',0Ah,0Dh,'$'
MSegm DW ? ;memory segments
Beg_X DW ? ;coordinate
Beg_Y DW ? ;variables
Dot_X DW ?
Dot_Y DW ?
XOld DW ?
YOld DW ?
Color DB 15 ;color variables
OldColor DB 15
Fon DB 0
Mode DB 0 ;modes
OldVideo DB ?
OldPage DB ?
Inc_X DW 0 ;coordinate
Inc_Y DW 0 ;increments
X1 DW 100 ;upper left
Y1 DW 15 ;corner
X2 DW 600 ;lower right
Y2 DW 315 ;corner
MStat DW ? ;mouse status
KBStatus DB ? ;keyboard status
Button_Number DW ? ;mouse button number
Old_33h_off DW ?
Old_33h_SEG DW ?
Message2 DB 'Mouse driver not installed,'
DB ' you',27h,'d better install it!',0Ah,0Dh
DB 'Please, strike any key ...','$'
;=========================================================
SET_UP: PUSH CS
POP DS
MOV AH,0Fh ;storing old video parameters
INT 10h
MOV OldVideo,AL
MOV OldPage,BH
MOV AH,9 ; do message
LEA DX,Message1;Type $-string
INT 21h
MOV AX,0C01h
INT 21h ;Wait for character input
;---------------------------------------------------------
; Checking, if the Mouse Driver is installed
MOV AX,0
MOV SI,7373h ;set parole
INT 33h ;Is our mouse driver installed?
CMP AX,0
JNE work ;Yes
MOV AH,9 ;Not installed,
LEA DX,Message2 ;type message
INT 21h
MOV AX,0C01h ;Wait for character input
INT 21h
;---------------------------------------------------------
work: MOV Button_Number,BX
MOV AX,15h ;Get necessary memory for mouse
MOV SI,7373h ;set parole
INT 33h
SHR BX,4 ;Byte to paragraphs
MOV AH,48h
INT 21h ;Allocate memory, if needs
MOV MSegm,AX;
MOV ES,AX
XOR DX,DX
MOV AX,16h
MOV SI,7373h ;set parole
INT 33h ;Save Mouse Driver State
;---------------------------------------------------------
MOV AX,MSegm ; the buffer is used for to pass
MOV ES,AX ; old Int 33h vector
MOV AX, ES:[0]
MOV Old_33h_off, AX
MOV AX, ES:[2]
MOV Old_33h_SEG, AX
CALL videoinit
MOV Inc_X,16 ;repeat number
;---------------------------------------------------------
r: CALL Rectangle ;frame creating
INC X1
INC Y1
DEC X2
DEC Y2
INC color
DEC Inc_X
JNZ r
;---------------------------------------------------------
MOV dot_X,240 ;put dot in the center
MOV dot_Y,165
CALL dot
;=========================================================
Tick:
;---------------------------------------------------------
; In this big cicle all hot keys as well as a mouse
; are periodically requested. If any information
;received, it transformed into program state change
;or in the requested action or motion
;---------------------------------------------------------
;get motion control information from mouse motion
PUSH CS
POP DS
MOV AX,3
MOV SI,7373h ;set parole
INT 33h ;get mouse status
MOV MStat,BX
TEST MStat,2 ;is right button pressed?
JZ motion
JMP Exit
motion:
MOV AX,0Bh ;get mouse replacement
MOV SI,7373h ;set parole
INT 33h
ADD Inc_X,CX ;light dot
ADD Inc_Y,DX ;motion
;---------------------------------------------------------
;get motion control information from keyboard
KB: MOV KBStatus,0
MOV AH,2
INT 16h
TEST AX,40h
JZ tt
MOV KBStatus,1
tt: MOV ah,0Bh
INT 21h
CMP AL,0 ;buffer is empty
JZ LSH
MOV AH,0
INT 16h
CMP AL,0
JZ C_up ;usual codes
CMP AL,9 ;tabulation
JNZ Out_
INC color
AND color,0fh
JMP LSH
Out_: CMP AL,27 ;exit, if ESC pressed
JNZ LSH
JMP Exit
; check for arrow codes
C_up: CMP AH,72 ;control codes
JNZ C_left
DEC Inc_Y
DEC Inc_Y
C_left: CMP AH,75
JNZ C_right
DEC Inc_X
DEC Inc_X
C_right:
CMP AH,77
JNZ C_down
INC Inc_X
INC Inc_X
C_down: CMP AH,80
JNZ LSH
INC Inc_Y
INC Inc_Y
;---------------------------------------------------------
;check for mouse button and keyboard control
LSH: MOV AH,2 ;check
INT 16h ;if pressed?
TEST MStat,1 ;mouse left button pressed?
JZ tls
MOV AL,2
tls: TEST AL,2 ;Is Left Shift pressed?
JNZ incr ;Shift
CALL Dot_Hide
incr: CALL XY_Increment
CALL Dot
JMP Tick
;====================SUBROUTINES==========================
videoinit: ; video controller initialization
MOV AH,0Fh
INT 10h
MOV OldVideo,AL
MOV AH,00 ;video setup
MOV AL,10h
INT 10h
MOV AH,11h ;setup graphics
MOV AL,22h ;from ROM
MOV BL,25
INT 10h
MOV AH,6
MOV AL,0
MOV BH,fon
MOV CX,0
MOV DX,184Fh
INT 10h
RET
;=========================================================
dot:
;this routine paints pixel
;DX=Y-coordinate;CX=X-coordinate; color = pixel color
MOV BH,0 ;display page
MOV CX,dot_X
MOV DX,dot_Y
MOV AH,0dh
INT 10h
MOV BX,XOld
CMP dot_X,BX
JZ Y_comp
MOV OldColor,AL
JMP SetColor
Y_comp:
MOV BX,YOld
CMP dot_Y,BX
JZ SetColor
MOV OldColor,AL
SetColor:
MOV BH,0 ;display page
MOV AL,color ;pixel color
MOV CX,dot_X
MOV XOld,CX
MOV DX,dot_Y
MOV YOld,DX
MOV AH,0Ch
INT 10h
RET
;=========================================================
Dot_Hide:
;this routine hides pixel
;DX=Y-coordinate;CX=X-coordinate; color = pixel color
MOV BH,0 ;display page
TEST KBStatus,1
JZ wipe ;fon_
MOV AL,OldColor
fff: MOV DX,dot_Y
MOV CX,dot_X
MOV AH,0Ch
INT 10h
RET
wipe: PUSH dot_Y
mov CX,6
w1: MOV AL,fon ;set pixel color
PUSH CX
call fff
POP CX
MOV AX,Y2
CMP Dot_Y,AX
JZ lw1
INC Dot_Y
lw1: LOOP w1
POP dot_Y
RET
;=========================================================
Rectangle:
;this routine draws rectangle
MOV mode,1 ;drow gorisontal line
MOV AX,Y2
MOV beg_Y,AX
MOV AX,X1
MOV beg_X,AX
MOV DI,X2
CALL _line
MOV AX,Y1 ;the same
MOV beg_Y,AX
MOV AX,X1
MOV beg_X,AX
MOV DI,X2
CALL _line
MOV mode,0 ;drow vertical line
MOV DI,Y2
CALL _line
MOV AX,X2 ; the same
MOV beg_X,AX
MOV DI,Y2
CALL _line
RET
;=========================================================
_line:
;drow the line ;beg_Y=Y-coordinate
;beg_X=X-coordinate
;DI= line end
; color = that of dot,
;mode=0 - vertical line
;mode <> 0 - gorisontal line;
;---------------------------------------------------------
MOV AX,beg_X
MOV dot_X,AX
MOV AX,beg_Y
MOV dot_Y,AX
a1: CALL dot ;put the first dot
CMP mode,0 ;mode choice
JNZ a2
JMP a3
a2: INC dot_X ;gorisontal line
CMP dot_X,DI
JNZ a1
RET
a3: INC dot_Y
CMP dot_Y,DI ;vertical line
JNZ a1
RET
;=========================================================
XY_Increment:
;---------------------------------------------------------
; This routine supports coordinate incrementing along with
; the boundary limiting logic
;---------------------------------------------------------
; X-coordinate handling
XOR AX,AX
CMP AX,Inc_X
JZ t2
JS t1
INC Inc_X
MOV AX,X1
CMP Dot_X,AX
JZ t2
DEC Dot_X
JMP t2
t1: DEC Inc_X
MOV AX,X2
CMP Dot_X,AX
JZ t2
INC Dot_X
; Y-coordinate handling
t2: XOR AX,AX
CMP AX,Inc_Y
JZ t4
JS t3
INC Inc_Y
MOV AX,Y1
CMP Dot_Y,AX
JZ t4
DEC Dot_Y
JMP t4
t3: DEC Inc_Y
MOV AX,Y2
CMP Dot_Y,AX
JZ t4
INC Dot_Y
t4: RET
;=========================================================
Exit:
; end routine actions
;---------------------------------------------------------
MOV AH,00 ; video reset
MOV AL,OldVideo ;
INT 10h
MOV AH,6 ;Clear Screen
MOV AL,0
MOV BH,7
XOR CX,CX
MOV DX,2479h
INT 10h
PUSH DS
PUSH Old_33h_off
PUSH Old_33h_SEG
POP DS
POP DX
MOV AX,MSegm
MOV ES,AX
MOV AH,49h
INT 21h ;return allocated buffer
MOV AH,4Ch
INT 21h ;program end
CSEG ENDS
END START
;*********************************************************